#pragma once


// CWaveCtrl
#define MARGIN_IN_LEFT 2
#define MARGIN_IN_TOP 2
#define MARGIN_IN_RIGHT 2
#define MARGIN_IN_BOTTOM 2

#define MARGIN_OUT_LEFT 0
#define MARGIN_OUT_TOP	MARGIN_OUT_LEFT
#define MARGIN_OUT_RIGHT	MARGIN_OUT_LEFT
#define MARGIN_OUT_BOTTOM	MARGIN_OUT_LEFT

#define COLOR_BK	RGB(180,180,180)

typedef enum
{
	SEL_LEFT, SEL_RIGHT, SEL_ZOOM
} EM_MOUSE_STATUS;

class CWaveCtrl : public CWnd
{
	DECLARE_DYNAMIC(CWaveCtrl)

public:
	CWaveCtrl();
	virtual ~CWaveCtrl();

	void SetData(int* data, int count)
	{
		m_Data = new int [count];
		memcpy(m_Data, data, sizeof(int)*count);
		m_Count = count;

		left = 0;
		right = m_Count;
//		Invalidate();
	}

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

protected:
	int* m_Data;
	int m_Count;

private:
	void DrawControl(CDC* pDC)
	{
		//pDC->DrawRectangle();
		CRect rectWnd;
		this->GetWindowRect(&rectWnd);
		ScreenToClient(&rectWnd);
		rectWnd.DeflateRect(MARGIN_OUT_LEFT, MARGIN_OUT_TOP);
		pDC->FillSolidRect(&rectWnd, COLOR_BK);
		pDC->Draw3dRect(&rectWnd, RGB(0,0,0), RGB(0,0,0));
	}


	void calcDelta()
	{
		CRect rectWnd;
		this->GetWindowRect(&rectWnd);
		ScreenToClient(&rectWnd);
		int width = rectWnd.Width() - (MARGIN_IN_LEFT + MARGIN_OUT_LEFT);
		int height = rectWnd.Height() - (MARGIN_IN_LEFT + MARGIN_OUT_LEFT);

		int count = right - left;
		dx = count;
		dx /= width;
		dy = 200;
		dy /= height;
	}
	int calcPos(const int pos)
	{
		float x = pos;
		x -= MARGIN_IN_LEFT + MARGIN_OUT_LEFT;
		x /= dx;
		return x;
	}
	int decalcPos(const int pos)
	{
		float x = pos;
		x += MARGIN_IN_LEFT + MARGIN_OUT_LEFT;
		x /= dx;
		return x;
	}

	int left, right;
	float dx, dy;
	int selLeft, selRight;
	BOOL isDown;
	int sel;

};


